package org.makcro.sms.services.chat.web.client.mvc;

import org.makcro.sms.services.chat.web.client.AppEvents;
import org.makcro.sms.services.chat.web.client.mvc.view.BulkTabView;
import org.makcro.sms.services.chat.web.client.services.message.BulkService;
import org.makcro.sms.services.chat.web.client.services.message.BulkServiceAsync;

import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.gwt.core.client.GWT;

/**
 * Bulk messages tab controller. Responsible for loading and searching bulk messages.
 * @author makcro
 *
 */
public class BulkTabController extends Controller {

	// bukl tab view
	private BulkTabView bulkTabView;
	
	// bulk messages service
	private BulkServiceAsync bulkServiceAsync;
	
	public BulkTabController() {
		registerEventTypes( AppEvents.BulkEvents.BULK_TAB_REQUESTED );
	}
	@Override
	protected void initialize() {
		super.initialize();
		this.bulkTabView = new BulkTabView( this );
		initRpcServices();
		
	}
	
	private void initRpcServices() {
		this.bulkServiceAsync = GWT.create( BulkService.class );
		
	}

	@Override
	public void handleEvent(AppEvent event) {
		EventType eventType = event.getType();
		if(eventType.equals( AppEvents.BulkEvents.BULK_TAB_REQUESTED )){
			onBulkTabRequested(event);
		}

	}

	/**
	 * Forwards event to the view
	 * @param event
	 */
	private void onBulkTabRequested(AppEvent event) {
		// forward event to view
		this.forwardToView( bulkTabView, event );
		
	}

}
